//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// Copyright 2012 Microsoft Corporation. All Rights Reserved
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.   
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

namespace Preflight.ServiceModel.Contract
{
    using System;
    using System.Collections.Generic;
    using System.Runtime.Serialization;

    [DataContract]
    [Serializable]
    public class Verification : IEquatable<Verification>
    {
        [DataMember]
        public bool Passed
        {
            get;
            set;
        }

        [DataMember]
        public string Name
        {
            get;
            set;
        }

        [DataMember]
        public List<PreflightMessage> Messages
        {
            get;
            set;
        }

        public bool Equals(Verification other)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }

            if (ReferenceEquals(this, other))
            {
                return true;
            }

            return
                this.Passed.Equals(other.Passed) &&
                string.Equals(this.Name, other.Name, StringComparison.InvariantCulture) &&
                this.Messages.ListItemsEqual(other.Messages);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
            {
                return false;
            }

            if (ReferenceEquals(this, obj))
            {
                return true;
            }

            if (obj.GetType() != this.GetType())
            {
                return false;
            }

            return this.Equals((Verification)obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int hashCode = this.Passed.GetHashCode();
                hashCode = (hashCode * 397) ^ (this.Name != null ? StringComparer.InvariantCulture.GetHashCode(this.Name) : 0);
                hashCode = (hashCode * 397) ^ (this.Messages != null ? this.Messages.CalculateHashCodeFromItems() : 0);
                return hashCode;
            }
        }
    }
}
